package com.smartwebx.ha.dal.realtime.sqlprovider;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.FROM;
import static org.apache.ibatis.jdbc.SqlBuilder.SELECT;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import java.util.Date;
import java.util.Map;

import org.apache.commons.lang3.time.DateUtils;

import com.smartwebx.ha.dal.config.OracleConfigInfo;
import com.smartwebx.ha.dal.usebean.enu.FlowTypeEnum;

public class RiverProvider {

	public String getDayFlowerProcessSQL(Map<String, Object> parameters) {
		BEGIN();
		FlowTypeEnum tabType = (FlowTypeEnum) parameters.get("tabType");
		Date endDate = (Date) parameters.get("endDate");
		if (endDate != null) {
			parameters.put("endDate", DateUtils.setHours(endDate, 8));
		}

		if (tabType == FlowTypeEnum.AVGFLOWER) {// 平均流量
			SELECT("AVQ val,IDTM tm");
			FROM(OracleConfigInfo.REALTIME_NAME + ".ST_RVAV_R");
			WHERE("STCD = #{stcd}");
			WHERE("IDTM >#{startDate}");
			WHERE("IDTM <= #{endDate}");
			WHERE("STTDRCD = '1'");
		} else if (tabType == FlowTypeEnum.DAYFLOWER) {// 日流量
			SELECT("Q val,TM tm");
			FROM(OracleConfigInfo.REALTIME_NAME + ".ST_RIVER_R");
			WHERE("STCD = #{stcd}");
			WHERE("TM > #{startDate}");
			WHERE("TM <= #{endDate}");
		}

		return SQL();
	}
}